/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.beynet.docs.format;

import java.io.IOException;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import org.beynet.docs.exceptions.GDocsServerError;
import org.beynet.docs.exceptions.UnexpectedStatusCode;
import org.beynet.docs.session.SessionFactory;

/**
 * represent a google doc collection
 *
 * @author beynet
 */
public class Collection {

    public Collection() {
        this.name = "Root";

    }

    public Collection(String name, URI self, URI contentFeedURI) {
        this.name = name;
        this.childs = null;
        this.self = self;
        this.contentFeedURI = contentFeedURI;
    }

    /**
     * the name of the collection
     *
     * @return
     */
    public String getName() {
        return (name);
    }

    /**
     * @return the collection self link
     */
    public URI getSelfURI() {
        return (self);
    }

    public URI getContentFeedURI() {
        return (this.contentFeedURI);
    }

    public List<Collection> getChilds() throws IOException, UnexpectedStatusCode, GDocsServerError {
        if (this.childs == null) {
            // retrieve current collection childs
            // ----------------------------------
            if (this.self == null) {
                this.childs = SessionFactory.getCurrentSession().getCollectionsAtRootLevel();
            } else {
                this.childs = new ArrayList<Collection>();
                SessionFactory.getCurrentSession().getCollectionChildsOfTypeCollection(contentFeedURI, childs);
            }
        }
        return (childs);
    }
    private URI contentFeedURI;
    private URI self;
    private String name;
    private List<Collection> childs;
}
